
//https://www.acwing.com/problem/content/910/


//先将每个区间右端点排序(从小到大)
//依次枚举当前左端点大于 上次最大左端点 集加入 ,贪心

#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=1e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
struct Range
{
    int l, r;
    bool operator< (const Range &W)const
    {
        return r < W.r;
    }
}range[N];

int main()
{
	close();
    cin>>n;
    for (int i = 0; i < n; i ++ ) cin>>range[i].l>>range[i].r;

    sort(range, range + n);

    int ans = 0, ed = -2e9;
    for (int i = 0; i < n; i ++ )
        if (ed < range[i].l)
        {
            ans ++ ;
            ed = range[i].r;
        }

    cout<<ans<<'\n';

    return 0;
}





